package com.nxn.core.web.action.base;

import java.io.Serializable;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

@ParentPackage("ajax-request")
@Results( { @Result(name = "reload", type="json", params={"excludeNullProperties","true","excludeProperties", "serviceImpl,model", "ignoreHierarchy","false"})} )
public abstract class DWZCRUDAction<T, PK extends Serializable> extends CRUDAction<T, PK>{
	private static final long serialVersionUID = 8487835304239158330L;
	
	/**
	 * DWZ AJAX 返回数据
	 * {"statusCode":"200", 
		"message":"操作成功", 
		"navTabId":"navNewsLi", 
		"forwardUrl":"", 
		"callbackType":"closeCurrent"}
	 */
	
	protected String statusCode = "200";
	protected String message = "操作成功";
	protected String navTabId = "";
	protected String forwardUrl;
	protected String callbackType = "closeCurrent";
	

	@Override
	public String save() throws Exception {
		String moduleTabName = getRequest().getRequestURI();
		moduleTabName = moduleTabName.substring(StringUtils.lastIndexOf(moduleTabName, "/")+1, StringUtils.indexOf(moduleTabName, "!"));
		
		setNavTabId(moduleTabName);
		return super.save();
	}
	
	@Override
	public String delete() throws Exception {
		setCallbackType(null);
		setNavTabId(null);
		
		return super.delete();
	}

	public String getStatusCode() {
		return statusCode;
	}

	public String getMessage() {
		return message;
	}

	public String getNavTabId() {
		return navTabId;
	}

	public String getForwardUrl() {
		return forwardUrl;
	}

	public String getCallbackType() {
		return callbackType;
	}

	public void setStatusCode(String statusCode) {
		this.statusCode = statusCode;
	}
	
	public void setMessage(String message) {
		this.message = message;
	}

	public void setNavTabId(String navTabId) {
		this.navTabId = navTabId;
	}

	public void setForwardUrl(String forwardUrl) {
		this.forwardUrl = forwardUrl;
	}

	public void setCallbackType(String callbackType) {
		this.callbackType = callbackType;
	}
}
